package com.ruoyi.project.declaration.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.declaration.domain.Files;
import com.ruoyi.project.declaration.service.IFilesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 文件Controller
 * 
 * @author Daniel
 * @date 2020-03-26
 */
@RestController
@RequestMapping("/declaration/files")
public class FilesController extends BaseController
{
    @Autowired
    private IFilesService filesService;

    /**
     * 查询文件列表
     */
    @PreAuthorize("@ss.hasPermi('declaration:files:list')")
    @GetMapping("/list")
    public TableDataInfo list(Files files)
    {
        startPage();
        List<Files> list = filesService.selectFilesList(files);
        return getDataTable(list);
    }

    /**
     * 导出文件列表
     */
    @PreAuthorize("@ss.hasPermi('declaration:files:export')")
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Files files)
    {
        List<Files> list = filesService.selectFilesList(files);
        ExcelUtil<Files> util = new ExcelUtil<Files>(Files.class);
        return util.exportExcel(list, "files");
    }

    /**
     * 获取文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('declaration:files:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId)
    {
        return AjaxResult.success(filesService.selectFilesById(fId));
    }

    /**
     * 新增文件
     */
    @PreAuthorize("@ss.hasPermi('declaration:files:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Files files)
    {
        return toAjax(filesService.insertFiles(files));
    }

    /**
     * 修改文件
     */
    @PreAuthorize("@ss.hasPermi('declaration:files:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Files files)
    {
        return toAjax(filesService.updateFiles(files));
    }

    /**
     * 删除文件
     */
    @PreAuthorize("@ss.hasPermi('declaration:files:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds)
    {
        return toAjax(filesService.deleteFilesByIds(fIds));
    }
}
